home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / info / lispref.info-21 < prev    next >
Encoding:
GNU Info File  |  1995-09-01  |  46.3 KB  |  1,086 lines

  1. This is Info file ../../info/lispref.info, produced by Makeinfo-1.63
  2. from the input file lispref.texi.
  3.  
  4.    Edition History:
  5.  
  6.    GNU Emacs Lisp Reference Manual Second Edition (v2.01), May 1993 GNU
  7. Emacs Lisp Reference Manual Further Revised (v2.02), August 1993 Lucid
  8. Emacs Lisp Reference Manual (for 19.10) First Edition, March 1994
  9. XEmacs Lisp Programmer's Manual (for 19.12) Second Edition, April 1995
  10. GNU Emacs Lisp Reference Manual v2.4, June 1995 XEmacs Lisp
  11. Programmer's Manual (for 19.13) Third Edition, July 1995
  12.  
  13.    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software
  14. Foundation, Inc.  Copyright (C) 1994, 1995 Sun Microsystems, Inc.
  15. Copyright (C) 1995 Amdahl Corporation.  Copyright (C) 1995 Ben Wing.
  16.  
  17.    Permission is granted to make and distribute verbatim copies of this
  18. manual provided the copyright notice and this permission notice are
  19. preserved on all copies.
  20.  
  21.    Permission is granted to copy and distribute modified versions of
  22. this manual under the conditions for verbatim copying, provided that the
  23. entire resulting derived work is distributed under the terms of a
  24. permission notice identical to this one.
  25.  
  26.    Permission is granted to copy and distribute translations of this
  27. manual into another language, under the above conditions for modified
  28. versions, except that this permission notice may be stated in a
  29. translation approved by the Foundation.
  30.  
  31.    Permission is granted to copy and distribute modified versions of
  32. this manual under the conditions for verbatim copying, provided also
  33. that the section entitled "GNU General Public License" is included
  34. exactly as in the original, and provided that the entire resulting
  35. derived work is distributed under the terms of a permission notice
  36. identical to this one.
  37.  
  38.    Permission is granted to copy and distribute translations of this
  39. manual into another language, under the above conditions for modified
  40. versions, except that the section entitled "GNU General Public License"
  41. may be included in a translation approved by the Free Software
  42. Foundation instead of in the original English.
  43.  
  44. 
  45. File: lispref.info,  Node: Magic File Names,  Next: Partial Files,  Prev: Create/Delete Dirs,  Up: Files
  46.  
  47. Making Certain File Names "Magic"
  48. =================================
  49.  
  50.    You can implement special handling for certain file names.  This is
  51. called making those names "magic".  You must supply a regular
  52. expression to define the class of names (all those that match the
  53. regular expression), plus a handler that implements all the primitive
  54. XEmacs file operations for file names that do match.
  55.  
  56.    The variable `file-name-handler-alist' holds a list of handlers,
  57. together with regular expressions that determine when to apply each
  58. handler.  Each element has this form:
  59.  
  60.      (REGEXP . HANDLER)
  61.  
  62. All the XEmacs primitives for file access and file name transformation
  63. check the given file name against `file-name-handler-alist'.  If the
  64. file name matches REGEXP, the primitives handle that file by calling
  65. HANDLER.
  66.  
  67.    The first argument given to HANDLER is the name of the primitive;
  68. the remaining arguments are the arguments that were passed to that
  69. operation.  (The first of these arguments is typically the file name
  70. itself.)  For example, if you do this:
  71.  
  72.      (file-exists-p FILENAME)
  73.  
  74. and FILENAME has handler HANDLER, then HANDLER is called like this:
  75.  
  76.      (funcall HANDLER 'file-exists-p FILENAME)
  77.  
  78.    Here are the operations that a magic file name handler gets to
  79. handle:
  80.  
  81. `add-name-to-file', `copy-file', `delete-directory', `delete-file',
  82. `diff-latest-backup-file', `directory-file-name', `directory-files',
  83. `dired-compress-file', `dired-uncache', `expand-file-name',
  84. `file-accessible-directory-p', `file-attributes', `file-directory-p',
  85. `file-executable-p', `file-exists-p', `file-local-copy', `file-modes',
  86. `file-name-all-completions', `file-name-as-directory',
  87. `file-name-completion', `file-name-directory', `file-name-nondirectory',
  88. `file-name-sans-versions', `file-newer-than-file-p', `file-readable-p',
  89. `file-regular-p', `file-symlink-p', `file-truename', `file-writable-p',
  90. `get-file-buffer', `insert-directory', `insert-file-contents', `load',
  91. `make-directory', `make-symbolic-link', `rename-file', `set-file-modes',
  92. `set-visited-file-modtime', `unhandled-file-name-directory',
  93. `verify-visited-file-modtime', `write-region'.
  94.  
  95.    Handlers for `insert-file-contents' typically need to clear the
  96. buffer's modified flag, with `(set-buffer-modified-p nil)', if the
  97. VISIT argument is non-`nil'.  This also has the effect of unlocking the
  98. buffer if it is locked.
  99.  
  100.    The handler function must handle all of the above operations, and
  101. possibly others to be added in the future.  It need not implement all
  102. these operations itself--when it has nothing special to do for a
  103. certain operation, it can reinvoke the primitive, to handle the
  104. operation "in the usual way".  It should always reinvoke the primitive
  105. for an operation it does not recognize.  Here's one way to do this:
  106.  
  107.      (defun my-file-handler (operation &rest args)
  108.        ;; First check for the specific operations
  109.        ;; that we have special handling for.
  110.        (cond ((eq operation 'insert-file-contents) ...)
  111.              ((eq operation 'write-region) ...)
  112.              ...
  113.              ;; Handle any operation we don't know about.
  114.              (t (let ((inhibit-file-name-handlers
  115.                       (cons 'my-file-handler
  116.                             (and (eq inhibit-file-name-operation operation)
  117.                                  inhibit-file-name-handlers)))
  118.                      (inhibit-file-name-operation operation))
  119.                   (apply operation args)))))
  120.  
  121.    When a handler function decides to call the ordinary Emacs primitive
  122. for the operation at hand, it needs to prevent the primitive from
  123. calling the same handler once again, thus leading to an infinite
  124. recursion.  The example above shows how to do this, with the variables
  125. `inhibit-file-name-handlers' and `inhibit-file-name-operation'.  Be
  126. careful to use them exactly as shown above; the details are crucial for
  127. proper behavior in the case of multiple handlers, and for operations
  128. that have two file names that may each have handlers.
  129.  
  130.  - Variable: inhibit-file-name-handlers
  131.      This variable holds a list of handlers whose use is presently
  132.      inhibited for a certain operation.
  133.  
  134.  - Variable: inhibit-file-name-operation
  135.      The operation for which certain handlers are presently inhibited.
  136.  
  137.  - Function: find-file-name-handler FILE OPERATION
  138.      This function returns the handler function for file name FILE, or
  139.      `nil' if there is none.  The argument OPERATION should be the
  140.      operation to be performed on the file--the value you will pass to
  141.      the handler as its first argument when you call it.  The operation
  142.      is needed for comparison with `inhibit-file-name-operation'.
  143.  
  144.  - Function: file-local-copy FILENAME
  145.      This function copies file FILENAME to an ordinary non-magic file,
  146.      if it isn't one already.
  147.  
  148.      If FILENAME specifies a "magic" file name, which programs outside
  149.      Emacs cannot directly read or write, this copies the contents to
  150.      an ordinary file and returns that file's name.
  151.  
  152.      If FILENAME is an ordinary file name, not magic, then this function
  153.      does nothing and returns `nil'.
  154.  
  155.  - Function: unhandled-file-name-directory FILENAME
  156.      This function returns the name of a directory that is not magic.
  157.      It uses the directory part of FILENAME if that is not magic.
  158.      Otherwise, it asks the handler what to do.
  159.  
  160.      This is useful for running a subprocess; every subprocess must
  161.      have a non-magic directory to serve as its current directory, and
  162.      this function is a good way to come up with one.
  163.  
  164. 
  165. File: lispref.info,  Node: Partial Files,  Next: Format Conversion,  Prev: Magic File Names,  Up: Files
  166.  
  167. Partial Files
  168. =============
  169.  
  170. * Menu:
  171.  
  172. * Intro to Partial Files::
  173. * Creating a Partial File::
  174. * Detached Partial Files::
  175.  
  176. 
  177. File: lispref.info,  Node: Intro to Partial Files,  Next: Creating a Partial File,  Up: Partial Files
  178.  
  179. Intro to Partial Files
  180. ----------------------
  181.  
  182.    A "partial file" is a section of a buffer (called the "master
  183. buffer") that is placed in its own buffer and treated as its own file.
  184. Changes made to the partial file are not reflected in the master buffer
  185. until the partial file is "saved" using the standard buffer save
  186. commands.  Partial files can be "reverted" (from the master buffer)
  187. just like normal files.  When a file part is active on a master buffer,
  188. that section of the master buffer is marked as read-only.  Two file
  189. parts on the same master buffer are not allowed to overlap.  Partial
  190. file buffers are indicated by the words `File Part' in the modeline.
  191.  
  192.    The master buffer knows about all the partial files that are active
  193. on it, and thus killing or reverting the master buffer will be handled
  194. properly.  When the master buffer is saved, if there are any unsaved
  195. partial files active on it then the user will be given the opportunity
  196. to first save these files.
  197.  
  198.    When a partial file buffer is first modified, the master buffer is
  199. automatically marked as modified so that saving the master buffer will
  200. work correctly.
  201.  
  202. 
  203. File: lispref.info,  Node: Creating a Partial File,  Next: Detached Partial Files,  Prev: Intro to Partial Files,  Up: Partial Files
  204.  
  205. Creating a Partial File
  206. -----------------------
  207.  
  208.  - Function: make-file-part &optional START END NAME BUFFER
  209.      Make a file part on buffer BUFFER out of the region.  Call it
  210.      NAME.  This command creates a new buffer containing the contents
  211.      of the region and marks the buffer as referring to the specified
  212.      buffer, called the "master buffer".  When the file-part buffer is
  213.      saved, its changes are integrated back into the master buffer.
  214.      When the master buffer is deleted, all file parts are deleted with
  215.      it.
  216.  
  217.      When called from a function, expects four arguments, START, END,
  218.      NAME, and BUFFER, all of which are optional and default to the
  219.      beginning of BUFFER, the end of BUFFER, a name generated from
  220.      BUFFER name, and the current buffer, respectively.
  221.  
  222. 
  223. File: lispref.info,  Node: Detached Partial Files,  Prev: Creating a Partial File,  Up: Partial Files
  224.  
  225. Detached Partial Files
  226. ----------------------
  227.  
  228.    Every partial file has an extent in the master buffer associated
  229. with it (called the "master extent"), marking where in the master
  230. buffer the partial file begins and ends.  If the text in master buffer
  231. that is contained by the extent is deleted, then the extent becomes
  232. "detached", meaning that it no longer refers to a specific region of
  233. the master buffer.  This can happen either when the text is deleted
  234. directly or when the master buffer is reverted.  Neither of these should
  235. happen in normal usage because the master buffer should generally not be
  236. edited directly.
  237.  
  238.    Before doing any operation that references a partial file's master
  239. extent, XEmacs checks to make sure that the extent is not detached.  If
  240. this is the case, XEmacs warns the user of this and the master extent is
  241. deleted out of the master buffer, disconnecting the file part.  The file
  242. part's filename is cleared and thus must be explicitly specified if the
  243. detached file part is to be saved.
  244.  
  245. 
  246. File: lispref.info,  Node: Format Conversion,  Next: Files and MS-DOS,  Prev: Partial Files,  Up: Files
  247.  
  248. File Format Conversion
  249. ======================
  250.  
  251.    The variable `format-alist' defines a list of "file formats", which
  252. describe textual representations used in files for the data (text,
  253. text-properties, and possibly other information) in an Emacs buffer.
  254. Emacs performs format conversion if appropriate when reading and writing
  255. files.
  256.  
  257.  - Variable: format-alist
  258.      This list contains one format definition for each defined file
  259.      format.
  260.  
  261.    Each format definition is a list of this form:
  262.  
  263.      (NAME DOC-STRING REGEXP FROM-FN TO-FN MODIFY MODE-FN)
  264.  
  265.    Here is what the elements in a format definition mean:
  266.  
  267. NAME
  268.      The name of this format.
  269.  
  270. DOC-STRING
  271.      A documentation string for the format.
  272.  
  273. REGEXP
  274.      A regular expression which is used to recognize files represented
  275.      in this format.
  276.  
  277. FROM-FN
  278.      A function to call to decode data in this format (to convert file
  279.      data into the usual Emacs data representation).
  280.  
  281.      The FROM-FN is called with two args, BEGIN and END, which specify
  282.      the part of the buffer it should convert.  It should convert the
  283.      text by editing it in place.  Since this can change the length of
  284.      the text, FROM-FN should return the modified end position.
  285.  
  286.      One responsibility of FROM-FN is to make sure that the beginning
  287.      of the file no longer matches REGEXP.  Otherwise it is likely to
  288.      get called again.
  289.  
  290. TO-FN
  291.      A function to call to encode data in this format (to convert the
  292.      usual Emacs data representation into this format).
  293.  
  294.      The TO-FN is called with two args, BEGIN and END, which specify
  295.      the part of the buffer it should convert.  There are two ways it
  296.      can do the conversion:
  297.  
  298.         * By editing the buffer in place.  In this case, TO-FN should
  299.           return the end-position of the range of text, as modified.
  300.  
  301.         * By returning a list of annotations.  This is a list of
  302.           elements of the form `(POSITION . STRING)', where POSITION is
  303.           an integer specifying the relative position in the text to be
  304.           written, and STRING is the annotation to add there.  The list
  305.           must be sorted in order of position when TO-FN returns it.
  306.  
  307.           When `write-region' actually writes the text from the buffer
  308.           to the file, it intermixes the specified annotations at the
  309.           corresponding positions.  All this takes place without
  310.           modifying the buffer.
  311.  
  312. MODIFY
  313.      A flag, `t' if the encoding function modifies the buffer, and
  314.      `nil' if it works by returning a list of annotations.
  315.  
  316. MODE
  317.      A mode function to call after visiting a file converted from this
  318.      format.
  319.  
  320.    The function `insert-file-contents' automatically recognizes file
  321. formats when it reads the specified file.  It checks the text of the
  322. beginning of the file against the regular expressions of the format
  323. definitions, and if it finds a match, it calls the decoding function for
  324. that format.  Then it checks all the known formats over again.  It
  325. keeps checking them until none of them is applicable.
  326.  
  327.    Visiting a file, with `find-file-noselect' or the commands that use
  328. it, performs conversion likewise (because it calls
  329. `insert-file-contents'); it also calls the mode function for each
  330. format that it decodes.  It stores a list of the format names in the
  331. buffer-local variable `buffer-file-format'.
  332.  
  333.  - Variable: buffer-file-format
  334.      This variable states the format of the visited file.  More
  335.      precisely, this is a list of the file format names that were
  336.      decoded in the course of visiting the current buffer's file.  It
  337.      is always local in all buffers.
  338.  
  339.    When `write-region' writes data into a file, it first calls the
  340. encoding functions for the formats listed in `buffer-file-format', in
  341. the order of appearance in the list.
  342.  
  343.  - Function: format-write-file FILE FORMAT
  344.      This command writes the current buffer contents into the file FILE
  345.      in format FORMAT, and makes that format the default for future
  346.      saves of the buffer.  The argument FORMAT is a list of format
  347.      names.
  348.  
  349.  - Function: format-find-file FILE FORMAT
  350.      This command finds the file FILE, converting it according to
  351.      format FORMAT.  It also makes FORMAT the default if the buffer is
  352.      saved later.
  353.  
  354.      The argument FORMAT is a list of format names.  If FORMAT is
  355.      `nil', no conversion takes place.  Interactively, typing just RET
  356.      for FORMAT specifies `nil'.
  357.  
  358.  - Function: format-insert-file FILE FORMAT %OPTIONAL BEG END
  359.      This command inserts the contents of file FILE, converting it
  360.      according to format FORMAT.  If BEG and END are non-`nil', they
  361.      specify which part of the file to read, as in
  362.      `insert-file-contents' (*note Reading from Files::.).
  363.  
  364.      The return value is like what `insert-file-contents' returns: a
  365.      list of the absolute file name and the length of the data inserted
  366.      (after conversion).
  367.  
  368.      The argument FORMAT is a list of format names.  If FORMAT is
  369.      `nil', no conversion takes place.  Interactively, typing just RET
  370.      for FORMAT specifies `nil'.
  371.  
  372.  - Function: format-find-file FILE FORMAT
  373.      This command finds the file FILE, converting it according to
  374.      format FORMAT.  It also makes FORMAT the default if the buffer is
  375.      saved later.
  376.  
  377.      The argument FORMAT is a list of format names.  If FORMAT is
  378.      `nil', no conversion takes place.  Interactively, typing just RET
  379.      for FORMAT specifies `nil'.
  380.  
  381.  - Function: format-insert-file FILE FORMAT %OPTIONAL BEG END
  382.      This command inserts the contents of file FILE, converting it
  383.      according to format FORMAT.  If BEG and END are non-`nil', they
  384.      specify which part of the file to read, as in
  385.      `insert-file-contents' (*note Reading from Files::.).
  386.  
  387.      The return value is like what `insert-file-contents' returns: a
  388.      list of the absolute file name and the length of the data inserted
  389.      (after conversion).
  390.  
  391.      The argument FORMAT is a list of format names.  If FORMAT is
  392.      `nil', no conversion takes place.  Interactively, typing just RET
  393.      for FORMAT specifies `nil'.
  394.  
  395.  - Variable: auto-save-file-format
  396.      This variable specifies the format to use for auto-saving.  Its
  397.      value is a list of format names, just like the value of
  398.      `buffer-file-format'; but it is used instead of
  399.      `buffer-file-format' for writing auto-save files.  This variable
  400.      is always local in all buffers.
  401.  
  402. 
  403. File: lispref.info,  Node: Files and MS-DOS,  Prev: Format Conversion,  Up: Files
  404.  
  405. Files and MS-DOS
  406. ================
  407.  
  408.    Emacs on MS-DOS makes a distinction between text files and binary
  409. files.  This is necessary because ordinary text files on MS-DOS use a
  410. two character sequence between lines: carriage-return and linefeed
  411. (CRLF).  Emacs expects just a newline character (a linefeed) between
  412. lines.  When Emacs reads or writes a text file on MS-DOS, it needs to
  413. convert the line separators.  This means it needs to know which files
  414. are text files and which are binary.  It makes this decision when
  415. visiting a file, and records the decision in the variable
  416. `buffer-file-type' for use when the file is saved.
  417.  
  418.    *Note MS-DOS Subprocesses::, for a related feature for subprocesses.
  419.  
  420.  - Variable: buffer-file-type
  421.      This variable, automatically local in each buffer, records the
  422.      file type of the buffer's visited file.  The value is `nil' for
  423.      text, `t' for binary.
  424.  
  425.  - Function: find-buffer-file-type FILENAME
  426.      This function determines whether file FILENAME is a text file or a
  427.      binary file.  It returns `nil' for text, `t' for binary.
  428.  
  429.  - User Option: file-name-buffer-file-type-alist
  430.      This variable holds an alist for distinguishing text files from
  431.      binary files.  Each element has the form (REGEXP . TYPE), where
  432.      REGEXP is matched against the file name, and TYPE may be is `nil'
  433.      for text, `t' for binary, or a function to call to compute which.
  434.      If it is a function, then it is called with a single argument (the
  435.      file name) and should return `t' or `nil'.
  436.  
  437.  - User Option: default-buffer-file-type
  438.      This variable specifies the default file type for files whose names
  439.      don't indicate anything in particular.  Its value should be `nil'
  440.      for text, or `t' for binary.
  441.  
  442.  - Command: find-file-text FILENAME
  443.      Like `find-file', but treat the file as text regardless of its
  444.      name.
  445.  
  446.  - Command: find-file-binary FILENAME
  447.      Like `find-file', but treat the file as binary regardless of its
  448.      name.
  449.  
  450. 
  451. File: lispref.info,  Node: Backups and Auto-Saving,  Next: Buffers,  Prev: Files,  Up: Top
  452.  
  453. Backups and Auto-Saving
  454. ***********************
  455.  
  456.    Backup files and auto-save files are two methods by which XEmacs
  457. tries to protect the user from the consequences of crashes or of the
  458. user's own errors.  Auto-saving preserves the text from earlier in the
  459. current editing session; backup files preserve file contents prior to
  460. the current session.
  461.  
  462. * Menu:
  463.  
  464. * Backup Files::   How backup files are made; how their names are chosen.
  465. * Auto-Saving::    How auto-save files are made; how their names are chosen.
  466. * Reverting::      `revert-buffer', and how to customize what it does.
  467.  
  468. 
  469. File: lispref.info,  Node: Backup Files,  Next: Auto-Saving,  Up: Backups and Auto-Saving
  470.  
  471. Backup Files
  472. ============
  473.  
  474.    A "backup file" is a copy of the old contents of a file you are
  475. editing.  XEmacs makes a backup file the first time you save a buffer
  476. into its visited file.  Normally, this means that the backup file
  477. contains the contents of the file as it was before the current editing
  478. session.  The contents of the backup file normally remain unchanged once
  479. it exists.
  480.  
  481.    Backups are usually made by renaming the visited file to a new name.
  482. Optionally, you can specify that backup files should be made by copying
  483. the visited file.  This choice makes a difference for files with
  484. multiple names; it also can affect whether the edited file remains owned
  485. by the original owner or becomes owned by the user editing it.
  486.  
  487.    By default, XEmacs makes a single backup file for each file edited.
  488. You can alternatively request numbered backups; then each new backup
  489. file gets a new name.  You can delete old numbered backups when you
  490. don't want them any more, or XEmacs can delete them automatically.
  491.  
  492. * Menu:
  493.  
  494. * Making Backups::     How XEmacs makes backup files, and when.
  495. * Rename or Copy::     Two alternatives: renaming the old file or copying it.
  496. * Numbered Backups::   Keeping multiple backups for each source file.
  497. * Backup Names::       How backup file names are computed; customization.
  498.  
  499. 
  500. File: lispref.info,  Node: Making Backups,  Next: Rename or Copy,  Up: Backup Files
  501.  
  502. Making Backup Files
  503. -------------------
  504.  
  505.  - Function: backup-buffer
  506.      This function makes a backup of the file visited by the current
  507.      buffer, if appropriate.  It is called by `save-buffer' before
  508.      saving the buffer the first time.
  509.  
  510.  - Variable: buffer-backed-up
  511.      This buffer-local variable indicates whether this buffer's file has
  512.      been backed up on account of this buffer.  If it is non-`nil', then
  513.      the backup file has been written.  Otherwise, the file should be
  514.      backed up when it is next saved (if backups are enabled).  This is
  515.      a permanent local; `kill-local-variables' does not alter it.
  516.  
  517.  - User Option: make-backup-files
  518.      This variable determines whether or not to make backup files.  If
  519.      it is non-`nil', then XEmacs creates a backup of each file when it
  520.      is saved for the first time--provided that `backup-inhibited' is
  521.      `nil' (see below).
  522.  
  523.      The following example shows how to change the `make-backup-files'
  524.      variable only in the `RMAIL' buffer and not elsewhere.  Setting it
  525.      `nil' stops XEmacs from making backups of the `RMAIL' file, which
  526.      may save disk space.  (You would put this code in your `.emacs'
  527.      file.)
  528.  
  529.           (add-hook 'rmail-mode-hook
  530.                     (function (lambda ()
  531.                                 (make-local-variable
  532.                                  'make-backup-files)
  533.                                 (setq make-backup-files nil))))
  534.  
  535.  - Variable: backup-enable-predicate
  536.      This variable's value is a function to be called on certain
  537.      occasions to decide whether a file should have backup files.  The
  538.      function receives one argument, a file name to consider.  If the
  539.      function returns `nil', backups are disabled for that file.
  540.      Otherwise, the other variables in this section say whether and how
  541.      to make backups.
  542.  
  543.      The default value is this:
  544.  
  545.           (lambda (name)
  546.             (or (< (length name) 5)
  547.                 (not (string-equal "/tmp/"
  548.                                    (substring name 0 5)))))
  549.  
  550.  - Variable: backup-inhibited
  551.      If this variable is non-`nil', backups are inhibited.  It records
  552.      the result of testing `backup-enable-predicate' on the visited file
  553.      name.  It can also coherently be used by other mechanisms that
  554.      inhibit backups based on which file is visited.  For example, VC
  555.      sets this variable non-`nil' to prevent making backups for files
  556.      managed with a version control system.
  557.  
  558.      This is a permanent local, so that changing the major mode does
  559.      not lose its value.  Major modes should not set this
  560.      variable--they should set `make-backup-files' instead.
  561.  
  562. 
  563. File: lispref.info,  Node: Rename or Copy,  Next: Numbered Backups,  Prev: Making Backups,  Up: Backup Files
  564.  
  565. Backup by Renaming or by Copying?
  566. ---------------------------------
  567.  
  568.    There are two ways that XEmacs can make a backup file:
  569.  
  570.    * XEmacs can rename the original file so that it becomes a backup
  571.      file, and then write the buffer being saved into a new file.
  572.      After this procedure, any other names (i.e., hard links) of the
  573.      original file now refer to the backup file.  The new file is owned
  574.      by the user doing the editing, and its group is the default for
  575.      new files written by the user in that directory.
  576.  
  577.    * XEmacs can copy the original file into a backup file, and then
  578.      overwrite the original file with new contents.  After this
  579.      procedure, any other names (i.e., hard links) of the original file
  580.      still refer to the current version of the file.  The file's owner
  581.      and group will be unchanged.
  582.  
  583.    The first method, renaming, is the default.
  584.  
  585.    The variable `backup-by-copying', if non-`nil', says to use the
  586. second method, which is to copy the original file and overwrite it with
  587. the new buffer contents.  The variable `file-precious-flag', if
  588. non-`nil', also has this effect (as a sideline of its main
  589. significance).  *Note Saving Buffers::.
  590.  
  591.  - Variable: backup-by-copying
  592.      If this variable is non-`nil', XEmacs always makes backup files by
  593.      copying.
  594.  
  595.    The following two variables, when non-`nil', cause the second method
  596. to be used in certain special cases.  They have no effect on the
  597. treatment of files that don't fall into the special cases.
  598.  
  599.  - Variable: backup-by-copying-when-linked
  600.      If this variable is non-`nil', XEmacs makes backups by copying for
  601.      files with multiple names (hard links).
  602.  
  603.      This variable is significant only if `backup-by-copying' is `nil',
  604.      since copying is always used when that variable is non-`nil'.
  605.  
  606.  - Variable: backup-by-copying-when-mismatch
  607.      If this variable is non-`nil', XEmacs makes backups by copying in
  608.      cases where renaming would change either the owner or the group of
  609.      the file.
  610.  
  611.      The value has no effect when renaming would not alter the owner or
  612.      group of the file; that is, for files which are owned by the user
  613.      and whose group matches the default for a new file created there
  614.      by the user.
  615.  
  616.      This variable is significant only if `backup-by-copying' is `nil',
  617.      since copying is always used when that variable is non-`nil'.
  618.  
  619. 
  620. File: lispref.info,  Node: Numbered Backups,  Next: Backup Names,  Prev: Rename or Copy,  Up: Backup Files
  621.  
  622. Making and Deleting Numbered Backup Files
  623. -----------------------------------------
  624.  
  625.    If a file's name is `foo', the names of its numbered backup versions
  626. are `foo.~V~', for various integers V, like this: `foo.~1~', `foo.~2~',
  627. `foo.~3~', ..., `foo.~259~', and so on.
  628.  
  629.  - User Option: version-control
  630.      This variable controls whether to make a single non-numbered backup
  631.      file or multiple numbered backups.
  632.  
  633.     `nil'
  634.           Make numbered backups if the visited file already has
  635.           numbered backups; otherwise, do not.
  636.  
  637.     `never'
  638.           Do not make numbered backups.
  639.  
  640.     ANYTHING ELSE
  641.           Make numbered backups.
  642.  
  643.    The use of numbered backups ultimately leads to a large number of
  644. backup versions, which must then be deleted.  XEmacs can do this
  645. automatically or it can ask the user whether to delete them.
  646.  
  647.  - User Option: kept-new-versions
  648.      The value of this variable is the number of newest versions to keep
  649.      when a new numbered backup is made.  The newly made backup is
  650.      included in the count.  The default value is 2.
  651.  
  652.  - User Option: kept-old-versions
  653.      The value of this variable is the number of oldest versions to keep
  654.      when a new numbered backup is made.  The default value is 2.
  655.  
  656.    If there are backups numbered 1, 2, 3, 5, and 7, and both of these
  657. variables have the value 2, then the backups numbered 1 and 2 are kept
  658. as old versions and those numbered 5 and 7 are kept as new versions;
  659. backup version 3 is excess.  The function `find-backup-file-name'
  660. (*note Backup Names::.) is responsible for determining which backup
  661. versions to delete, but does not delete them itself.
  662.  
  663.  - User Option: trim-versions-without-asking
  664.      If this variable is non-`nil', then saving a file deletes excess
  665.      backup versions silently.  Otherwise, it asks the user whether to
  666.      delete them.
  667.  
  668.  - User Option: dired-kept-versions
  669.      This variable specifies how many of the newest backup versions to
  670.      keep in the Dired command `.' (`dired-clean-directory').  That's
  671.      the same thing `kept-new-versions' specifies when you make a new
  672.      backup file.  The default value is 2.
  673.  
  674. 
  675. File: lispref.info,  Node: Backup Names,  Prev: Numbered Backups,  Up: Backup Files
  676.  
  677. Naming Backup Files
  678. -------------------
  679.  
  680.    The functions in this section are documented mainly because you can
  681. customize the naming conventions for backup files by redefining them.
  682. If you change one, you probably need to change the rest.
  683.  
  684.  - Function: backup-file-name-p FILENAME
  685.      This function returns a non-`nil' value if FILENAME is a possible
  686.      name for a backup file.  A file with the name FILENAME need not
  687.      exist; the function just checks the name.
  688.  
  689.           (backup-file-name-p "foo")
  690.                => nil
  691.  
  692.           (backup-file-name-p "foo~")
  693.                => 3
  694.  
  695.      The standard definition of this function is as follows:
  696.  
  697.           (defun backup-file-name-p (file)
  698.             "Return non-nil if FILE is a backup file \
  699.           name (numeric or not)..."
  700.             (string-match "~$" file))
  701.  
  702.      Thus, the function returns a non-`nil' value if the file name ends
  703.      with a `~'.  (We use a backslash to split the documentation
  704.      string's first line into two lines in the text, but produce just
  705.      one line in the string itself.)
  706.  
  707.      This simple expression is placed in a separate function to make it
  708.      easy to redefine for customization.
  709.  
  710.  - Function: make-backup-file-name FILENAME
  711.      This function returns a string that is the name to use for a
  712.      non-numbered backup file for file FILENAME.  On Unix, this is just
  713.      FILENAME with a tilde appended.
  714.  
  715.      The standard definition of this function is as follows:
  716.  
  717.           (defun make-backup-file-name (file)
  718.             "Create the non-numeric backup file name for FILE.
  719.           ..."
  720.             (concat file "~"))
  721.  
  722.      You can change the backup-file naming convention by redefining this
  723.      function.  The following example redefines `make-backup-file-name'
  724.      to prepend a `.' in addition to appending a tilde:
  725.  
  726.           (defun make-backup-file-name (filename)
  727.             (concat "." filename "~"))
  728.  
  729.           (make-backup-file-name "backups.texi")
  730.                => ".backups.texi~"
  731.  
  732.  - Function: find-backup-file-name FILENAME
  733.      This function computes the file name for a new backup file for
  734.      FILENAME.  It may also propose certain existing backup files for
  735.      deletion.  `find-backup-file-name' returns a list whose CAR is the
  736.      name for the new backup file and whose CDR is a list of backup
  737.      files whose deletion is proposed.
  738.  
  739.      Two variables, `kept-old-versions' and `kept-new-versions',
  740.      determine which backup versions should be kept.  This function
  741.      keeps those versions by excluding them from the CDR of the value.
  742.      *Note Numbered Backups::.
  743.  
  744.      In this example, the value says that `~rms/foo.~5~' is the name to
  745.      use for the new backup file, and `~rms/foo.~3~' is an "excess"
  746.      version that the caller should consider deleting now.
  747.  
  748.           (find-backup-file-name "~rms/foo")
  749.                => ("~rms/foo.~5~" "~rms/foo.~3~")
  750.  
  751.  - Function: file-newest-backup FILENAME
  752.      This function returns the name of the most recent backup file for
  753.      FILENAME, or `nil' if that file has no backup files.
  754.  
  755.      Some file comparison commands use this function so that they can
  756.      automatically compare a file with its most recent backup.
  757.  
  758. 
  759. File: lispref.info,  Node: Auto-Saving,  Next: Reverting,  Prev: Backup Files,  Up: Backups and Auto-Saving
  760.  
  761. Auto-Saving
  762. ===========
  763.  
  764.    XEmacs periodically saves all files that you are visiting; this is
  765. called "auto-saving".  Auto-saving prevents you from losing more than a
  766. limited amount of work if the system crashes.  By default, auto-saves
  767. happen every 300 keystrokes, or after around 30 seconds of idle time.
  768. *Note Auto-Save: (emacs)Auto-Save, for information on auto-save for
  769. users.  Here we describe the functions used to implement auto-saving
  770. and the variables that control them.
  771.  
  772.  - Variable: buffer-auto-save-file-name
  773.      This buffer-local variable is the name of the file used for
  774.      auto-saving the current buffer.  It is `nil' if the buffer should
  775.      not be auto-saved.
  776.  
  777.           buffer-auto-save-file-name
  778.           => "/xcssun/users/rms/lewis/#files.texi#"
  779.  
  780.  - Command: auto-save-mode ARG
  781.      When used interactively without an argument, this command is a
  782.      toggle switch: it turns on auto-saving of the current buffer if it
  783.      is off, and vice-versa.  With an argument ARG, the command turns
  784.      auto-saving on if the value of ARG is `t', a nonempty list, or a
  785.      positive integer.  Otherwise, it turns auto-saving off.
  786.  
  787.  - Function: auto-save-file-name-p FILENAME
  788.      This function returns a non-`nil' value if FILENAME is a string
  789.      that could be the name of an auto-save file.  It works based on
  790.      knowledge of the naming convention for auto-save files: a name that
  791.      begins and ends with hash marks (`#') is a possible auto-save file
  792.      name.  The argument FILENAME should not contain a directory part.
  793.  
  794.           (make-auto-save-file-name)
  795.                => "/xcssun/users/rms/lewis/#files.texi#"
  796.           (auto-save-file-name-p "#files.texi#")
  797.                => 0
  798.           (auto-save-file-name-p "files.texi")
  799.                => nil
  800.  
  801.      The standard definition of this function is as follows:
  802.  
  803.           (defun auto-save-file-name-p (filename)
  804.             "Return non-nil if FILENAME can be yielded by..."
  805.             (string-match "^#.*#$" filename))
  806.  
  807.      This function exists so that you can customize it if you wish to
  808.      change the naming convention for auto-save files.  If you redefine
  809.      it, be sure to redefine the function `make-auto-save-file-name'
  810.      correspondingly.
  811.  
  812.  - Function: make-auto-save-file-name
  813.      This function returns the file name to use for auto-saving the
  814.      current buffer.  This is just the file name with hash marks (`#')
  815.      appended and prepended to it.  This function does not look at the
  816.      variable `auto-save-visited-file-name' (described below); you
  817.      should check that before calling this function.
  818.  
  819.           (make-auto-save-file-name)
  820.                => "/xcssun/users/rms/lewis/#backup.texi#"
  821.  
  822.      The standard definition of this function is as follows:
  823.  
  824.           (defun make-auto-save-file-name ()
  825.             "Return file name to use for auto-saves \
  826.           of current buffer.
  827.           ..."
  828.             (if buffer-file-name
  829.                 (concat
  830.                  (file-name-directory buffer-file-name)
  831.                  "#"
  832.                  (file-name-nondirectory buffer-file-name)
  833.                  "#")
  834.               (expand-file-name
  835.                (concat "#%" (buffer-name) "#"))))
  836.  
  837.      This exists as a separate function so that you can redefine it to
  838.      customize the naming convention for auto-save files.  Be sure to
  839.      change `auto-save-file-name-p' in a corresponding way.
  840.  
  841.  - Variable: auto-save-visited-file-name
  842.      If this variable is non-`nil', XEmacs auto-saves buffers in the
  843.      files they are visiting.  That is, the auto-save is done in the
  844.      same file that you are editing.  Normally, this variable is `nil',
  845.      so auto-save files have distinct names that are created by
  846.      `make-auto-save-file-name'.
  847.  
  848.      When you change the value of this variable, the value does not take
  849.      effect until the next time auto-save mode is reenabled in any given
  850.      buffer.  If auto-save mode is already enabled, auto-saves continue
  851.      to go in the same file name until `auto-save-mode' is called again.
  852.  
  853.  - Function: recent-auto-save-p
  854.      This function returns `t' if the current buffer has been
  855.      auto-saved since the last time it was read in or saved.
  856.  
  857.  - Function: set-buffer-auto-saved
  858.      This function marks the current buffer as auto-saved.  The buffer
  859.      will not be auto-saved again until the buffer text is changed
  860.      again.  The function returns `nil'.
  861.  
  862.  - User Option: auto-save-interval
  863.      The value of this variable is the number of characters that XEmacs
  864.      reads from the keyboard between auto-saves.  Each time this many
  865.      more characters are read, auto-saving is done for all buffers in
  866.      which it is enabled.
  867.  
  868.  - User Option: auto-save-timeout
  869.      The value of this variable is the number of seconds of idle time
  870.      that should cause auto-saving.  Each time the user pauses for this
  871.      long, XEmacs auto-saves any buffers that need it.  (Actually, the
  872.      specified timeout is multiplied by a factor depending on the size
  873.      of the current buffer.)
  874.  
  875.  - Variable: auto-save-hook
  876.      This normal hook is run whenever an auto-save is about to happen.
  877.  
  878.  - User Option: auto-save-default
  879.      If this variable is non-`nil', buffers that are visiting files
  880.      have auto-saving enabled by default.  Otherwise, they do not.
  881.  
  882.  - Command: do-auto-save &optional NO-MESSAGE CURRENT-ONLY
  883.      This function auto-saves all buffers that need to be auto-saved.
  884.      It saves all buffers for which auto-saving is enabled and that
  885.      have been changed since the previous auto-save.
  886.  
  887.      Normally, if any buffers are auto-saved, a message that says
  888.      `Auto-saving...' is displayed in the echo area while auto-saving is
  889.      going on.  However, if NO-MESSAGE is non-`nil', the message is
  890.      inhibited.
  891.  
  892.      If CURRENT-ONLY is non-`nil', only the current buffer is
  893.      auto-saved.
  894.  
  895.  - Function: delete-auto-save-file-if-necessary
  896.      This function deletes the current buffer's auto-save file if
  897.      `delete-auto-save-files' is non-`nil'.  It is called every time a
  898.      buffer is saved.
  899.  
  900.  - Variable: delete-auto-save-files
  901.      This variable is used by the function
  902.      `delete-auto-save-file-if-necessary'.  If it is non-`nil', Emacs
  903.      deletes auto-save files when a true save is done (in the visited
  904.      file).  This saves disk space and unclutters your directory.
  905.  
  906.  - Function: rename-auto-save-file
  907.      This function adjusts the current buffer's auto-save file name if
  908.      the visited file name has changed.  It also renames an existing
  909.      auto-save file.  If the visited file name has not changed, this
  910.      function does nothing.
  911.  
  912.  - Variable: buffer-saved-size
  913.      The value of this buffer-local variable is the length of the
  914.      current buffer as of the last time it was read in, saved, or
  915.      auto-saved.  This is used to detect a substantial decrease in
  916.      size, and turn off auto-saving in response.
  917.  
  918.      If it is -1, that means auto-saving is temporarily shut off in this
  919.      buffer due to a substantial deletion.  Explicitly saving the buffer
  920.      stores a positive value in this variable, thus reenabling
  921.      auto-saving.  Turning auto-save mode off or on also alters this
  922.      variable.
  923.  
  924.  - Variable: auto-save-list-file-name
  925.      This variable (if non-`nil') specifies a file for recording the
  926.      names of all the auto-save files.  Each time XEmacs does
  927.      auto-saving, it writes two lines into this file for each buffer
  928.      that has auto-saving enabled.  The first line gives the name of
  929.      the visited file (it's empty if the buffer has none), and the
  930.      second gives the name of the auto-save file.
  931.  
  932.      If XEmacs exits normally, it deletes this file.  If XEmacs
  933.      crashes, you can look in the file to find all the auto-save files
  934.      that might contain work that was otherwise lost.  The
  935.      `recover-session' command uses these files.
  936.  
  937.      The default name for this file is in your home directory and
  938.      starts with `.saves-'.  It also contains the XEmacs process ID and
  939.      the host name.
  940.  
  941. 
  942. File: lispref.info,  Node: Reverting,  Prev: Auto-Saving,  Up: Backups and Auto-Saving
  943.  
  944. Reverting
  945. =========
  946.  
  947.    If you have made extensive changes to a file and then change your
  948. mind about them, you can get rid of them by reading in the previous
  949. version of the file with the `revert-buffer' command.  *Note Reverting
  950. a Buffer: (emacs)Reverting.
  951.  
  952.  - Command: revert-buffer &optional CHECK-AUTO-SAVE NOCONFIRM
  953.      This command replaces the buffer text with the text of the visited
  954.      file on disk.  This action undoes all changes since the file was
  955.      visited or saved.
  956.  
  957.      If the argument CHECK-AUTO-SAVE is non-`nil', and the latest
  958.      auto-save file is more recent than the visited file,
  959.      `revert-buffer' asks the user whether to use that instead.
  960.      Otherwise, it always uses the text of the visited file itself.
  961.      Interactively, CHECK-AUTO-SAVE is set if there is a numeric prefix
  962.      argument.
  963.  
  964.      Normally, `revert-buffer' asks for confirmation before it changes
  965.      the buffer; but if the argument NOCONFIRM is non-`nil',
  966.      `revert-buffer' does not ask for confirmation.
  967.  
  968.      Reverting tries to preserve marker positions in the buffer by
  969.      using the replacement feature of `insert-file-contents'.  If the
  970.      buffer contents and the file contents are identical before the
  971.      revert operation, reverting preserves all the markers.  If they
  972.      are not identical, reverting does change the buffer; then it
  973.      preserves the markers in the unchanged text (if any) at the
  974.      beginning and end of the buffer.  Preserving any additional
  975.      markers would be problematical.
  976.  
  977.    You can customize how `revert-buffer' does its work by setting these
  978. variables--typically, as buffer-local variables.
  979.  
  980.  - Variable: revert-buffer-function
  981.      The value of this variable is the function to use to revert this
  982.      buffer.  If non-`nil', it is called as a function with no
  983.      arguments to do the work of reverting.  If the value is `nil',
  984.      reverting works the usual way.
  985.  
  986.      Modes such as Dired mode, in which the text being edited does not
  987.      consist of a file's contents but can be regenerated in some other
  988.      fashion, give this variable a buffer-local value that is a
  989.      function to regenerate the contents.
  990.  
  991.  - Variable: revert-buffer-insert-file-contents-function
  992.      The value of this variable, if non-`nil', is the function to use to
  993.      insert the updated contents when reverting this buffer.  The
  994.      function receives two arguments: first the file name to use;
  995.      second, `t' if the user has asked to read the auto-save file.
  996.  
  997.  - Variable: before-revert-hook
  998.      This normal hook is run by `revert-buffer' before actually
  999.      inserting the modified contents--but only if
  1000.      `revert-buffer-function' is `nil'.
  1001.  
  1002.      Font Lock mode uses this hook to record that the buffer contents
  1003.      are no longer fontified.
  1004.  
  1005.  - Variable: after-revert-hook
  1006.      This normal hook is run by `revert-buffer' after actually inserting
  1007.      the modified contents--but only if `revert-buffer-function' is
  1008.      `nil'.
  1009.  
  1010.      Font Lock mode uses this hook to recompute the fonts for the
  1011.      updated buffer contents.
  1012.  
  1013. 
  1014. File: lispref.info,  Node: Buffers,  Next: Windows,  Prev: Backups and Auto-Saving,  Up: Top
  1015.  
  1016. Buffers
  1017. *******
  1018.  
  1019.    A "buffer" is a Lisp object containing text to be edited.  Buffers
  1020. are used to hold the contents of files that are being visited; there may
  1021. also be buffers that are not visiting files.  While several buffers may
  1022. exist at one time, exactly one buffer is designated the "current
  1023. buffer" at any time.  Most editing commands act on the contents of the
  1024. current buffer.  Each buffer, including the current buffer, may or may
  1025. not be displayed in any windows.
  1026.  
  1027. * Menu:
  1028.  
  1029. * Buffer Basics::       What is a buffer?
  1030. * Current Buffer::      Designating a buffer as current
  1031.                           so primitives will access its contents.
  1032. * Buffer Names::        Accessing and changing buffer names.
  1033. * Buffer File Name::    The buffer file name indicates which file is visited.
  1034. * Buffer Modification:: A buffer is "modified" if it needs to be saved.
  1035. * Modification Time::   Determining whether the visited file was changed
  1036.                          "behind XEmacs's back".
  1037. * Read Only Buffers::   Modifying text is not allowed in a read-only buffer.
  1038. * The Buffer List::     How to look at all the existing buffers.
  1039. * Creating Buffers::    Functions that create buffers.
  1040. * Killing Buffers::     Buffers exist until explicitly killed.
  1041. * Indirect Buffers::    An indirect buffer shares text with some other buffer.
  1042.  
  1043. 
  1044. File: lispref.info,  Node: Buffer Basics,  Next: Current Buffer,  Up: Buffers
  1045.  
  1046. Buffer Basics
  1047. =============
  1048.  
  1049.    A "buffer" is a Lisp object containing text to be edited.  Buffers
  1050. are used to hold the contents of files that are being visited; there may
  1051. also be buffers that are not visiting files.  While several buffers may
  1052. exist at one time, exactly one buffer is designated the "current
  1053. buffer" at any time.  Most editing commands act on the contents of the
  1054. current buffer.  Each buffer, including the current buffer, may or may
  1055. not be displayed in any windows.
  1056.  
  1057.    Buffers in Emacs editing are objects that have distinct names and
  1058. hold text that can be edited.  Buffers appear to Lisp programs as a
  1059. special data type.  You can think of the contents of a buffer as an
  1060. extendable string; insertions and deletions may occur in any part of
  1061. the buffer.  *Note Text::.
  1062.  
  1063.    A Lisp buffer object contains numerous pieces of information.  Some
  1064. of this information is directly accessible to the programmer through
  1065. variables, while other information is accessible only through
  1066. special-purpose functions.  For example, the visited file name is
  1067. directly accessible through a variable, while the value of point is
  1068. accessible only through a primitive function.
  1069.  
  1070.    Buffer-specific information that is directly accessible is stored in
  1071. "buffer-local" variable bindings, which are variable values that are
  1072. effective only in a particular buffer.  This feature allows each buffer
  1073. to override the values of certain variables.  Most major modes override
  1074. variables such as `fill-column' or `comment-column' in this way.  For
  1075. more information about buffer-local variables and functions related to
  1076. them, see *Note Buffer-Local Variables::.
  1077.  
  1078.    For functions and variables related to visiting files in buffers, see
  1079. *Note Visiting Files:: and *Note Saving Buffers::.  For functions and
  1080. variables related to the display of buffers in windows, see *Note
  1081. Buffers and Windows::.
  1082.  
  1083.  - Function: bufferp OBJECT
  1084.      This function returns `t' if OBJECT is a buffer, `nil' otherwise.
  1085.  
  1086.